{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## list\n",
    "list是有序的"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1.产品用户\n",
      "['liangdianshui', 'twowater', '两点水']\n"
     ]
    }
   ],
   "source": [
    "# -*-coding:utf-8-*-\n",
    "user = ['liangdianshui', 'twowater', '两点水']\n",
    "print('1.产品用户')\n",
    "print(user)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(user)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "liangdianshui,twowater,两点水\n"
     ]
    }
   ],
   "source": [
    "print(user[0] + ',' + user[1] + ',' + user[2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['liangdianshui', 'twowater', '两点水', '茵茵']\n"
     ]
    }
   ],
   "source": [
    "user.append('茵茵')\n",
    "print(user)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'茵茵'"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "user.pop()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['liangdianshui', 'twowater', '两点水']\n"
     ]
    }
   ],
   "source": [
    "print(user)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'twowater'"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "user.pop(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['liangdianshui', '两点水']\n"
     ]
    }
   ],
   "source": [
    "print(user)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['liangdianshui', '三点水']\n",
      "['liangdianshui', 'hello', '三点水']\n"
     ]
    }
   ],
   "source": [
    "user[1] = '三点水'\n",
    "print(user)\n",
    "user.insert(1, 'hello')\n",
    "print(user)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# tuple\n",
    "初始化后不可修改"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(123,)\n"
     ]
    }
   ],
   "source": [
    "tuple1 = (123,)\n",
    "print(tuple1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# dict\n",
    "key-value"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'一点水': '131456780001', '两点水': '131456780002', '三点水': '131456780003', '四点水': '131456780004', '五点水': '131456780005'}\n"
     ]
    }
   ],
   "source": [
    "name = {'一点水': '131456780001',\n",
    "        '两点水': '131456780002', \n",
    "        '三点水': '131456780003', \n",
    "        '四点水': '131456780004',\n",
    "        '五点水': '131456780005'}\n",
    "print(name)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "dict_items([('一点水', '131456780001'), ('两点水', '131456780002'), ('三点水', '131456780003'), ('四点水', '131456780004'), ('五点水', '131456780005')])\n"
     ]
    }
   ],
   "source": [
    "list = name.items()\n",
    "print(list)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# set\n",
    "无序不循环元素集"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{456, 123, 789}\n"
     ]
    }
   ],
   "source": [
    "set1 = set([123, 456, 789])\n",
    "print(set1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{456, 123, 100, 789}\n"
     ]
    }
   ],
   "source": [
    "set1.add(100)\n",
    "print(set1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{123, 100, 789}\n"
     ]
    }
   ],
   "source": [
    "set1.remove(456)\n",
    "print(set1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'h', 'e', 'o', 'l'}\n",
      "{'h', 'p', 'y', 'o', 'n'}\n",
      "\n",
      "交集 set3:\n",
      "{'h', 'o'}\n",
      "\n",
      "并集 set4:\n",
      "{'h', 'p', 'e', 'y', 'o', 'l', 'n'}\n",
      "\n",
      "差集 set5:\n",
      "{'e', 'l'}\n",
      "\n",
      "差集 set6:\n",
      "{'y', 'n', 'p'}\n",
      "\n",
      "去除列表里重复元素 set7:\n",
      "{555, 333, 111, 666, 444, 222}\n"
     ]
    }
   ],
   "source": [
    "set1=set('hello')\n",
    "set2=set(['p','y','y','h','o','n'])\n",
    "print(set1)\n",
    "print(set2)\n",
    "\n",
    "# 交集 (求两个 set 集合中相同的元素)\n",
    "set3=set1 & set2\n",
    "print('\\n交集 set3:')\n",
    "print(set3)\n",
    "# 并集 （合并两个 set 集合的元素并去除重复的值）\n",
    "set4=set1 | set2\n",
    "print('\\n并集 set4:')\n",
    "print(set4)\n",
    "# 差集\n",
    "set5=set1 - set2\n",
    "set6=set2 - set1\n",
    "print('\\n差集 set5:')\n",
    "print(set5)\n",
    "print('\\n差集 set6:')\n",
    "print( set6)\n",
    "\n",
    "\n",
    "# 去除海量列表里重复元素，用 hash 来解决也行，只不过感觉在性能上不是很高，用 set 解决还是很不错的\n",
    "list1 = [111,222,333,444,111,222,333,444,555,666]  \n",
    "set7=set(list1)\n",
    "print('\\n去除列表里重复元素 set7:')\n",
    "print(set7)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "5\n"
     ]
    }
   ],
   "source": [
    "count = 0\n",
    "while count < 5:\n",
    "    print(count)\n",
    "    count = count + 1\n",
    "else:\n",
    "    print(count)\n",
    "    count += 1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 迭代器"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<str_iterator object at 0x000001C1943506A0>\n",
      "l i a n g d i a n s h u i "
     ]
    }
   ],
   "source": [
    "str1 = 'liangdianshui'\n",
    "iter1 = iter(str1)\n",
    "print(iter1)\n",
    "for x in iter1:\n",
    "    print(x, end=' ')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1x1= 1\n",
      "1x2= 2 2x2= 4\n",
      "1x3= 3 2x3= 6 3x3= 9\n",
      "1x4= 4 2x4= 8 3x4=12 4x4=16\n",
      "1x5= 5 2x5=10 3x5=15 4x5=20 5x5=25\n",
      "1x6= 6 2x6=12 3x6=18 4x6=24 5x6=30 6x6=36\n",
      "1x7= 7 2x7=14 3x7=21 4x7=28 5x7=35 6x7=42 7x7=49\n",
      "1x8= 8 2x8=16 3x8=24 4x8=32 5x8=40 6x8=48 7x8=56 8x8=64\n",
      "1x9= 9 2x9=18 3x9=27 4x9=36 5x9=45 6x9=54 7x9=63 8x9=72 9x9=81\n"
     ]
    }
   ],
   "source": [
    "print('\\n'.join([' '.join('%dx%d=%2d' % (x,y,x*y) for x in range(1, y+1)) for y in range(1, 10)]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "l i a n g d i a n s h u i\n"
     ]
    }
   ],
   "source": [
    "print(' '.join(str1))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 生成器"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<generator object <genexpr> at 0x000001C1943F6048>\n",
      "0 1 4 9 16 25 36 49 64 81 "
     ]
    }
   ],
   "source": [
    "gen = (x * x for x in range(10))\n",
    "print(gen)\n",
    "# for num in gen:\n",
    "#     print(num, end=' ')\n",
    "while True:\n",
    "    try:\n",
    "        print(next(gen), end=' ')\n",
    "    except StopIteration:\n",
    "        break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 1 2 3 5 8 13 21 34 55 "
     ]
    }
   ],
   "source": [
    "def fibon(n):\n",
    "    a = b = 1\n",
    "    for i in range(n):\n",
    "        yield a\n",
    "        a, b = b, a + b\n",
    "\n",
    "fibon10 = fibon(10)\n",
    "for x in fibon10:\n",
    "    print(x, end=' ')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1]\n",
      "[1, 1]\n",
      "[1, 2, 1]\n",
      "[1, 3, 3, 1]\n",
      "[1, 4, 6, 4, 1]\n",
      "[1, 5, 10, 10, 5, 1]\n",
      "[1, 6, 15, 20, 15, 6, 1]\n",
      "[1, 7, 21, 35, 35, 21, 7, 1]\n",
      "[1, 8, 28, 56, 70, 56, 28, 8, 1]\n",
      "[1, 9, 36, 84, 126, 126, 84, 36, 9, 1]\n"
     ]
    }
   ],
   "source": [
    "# 杨辉三角\n",
    "def triangles(n):\n",
    "    L = [1]\n",
    "    while True:\n",
    "        yield L\n",
    "        L.append(0)\n",
    "        L = [L[i - 1] + L[i] for i in range(len(L))]\n",
    "\n",
    "n = 0\n",
    "for t in triangles(10):\n",
    "    print(t)\n",
    "    n = n + 1\n",
    "    if n == 10:\n",
    "        break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['d:\\\\env\\\\pytorch\\\\scripts\\\\python36.zip', 'd:\\\\env\\\\pytorch\\\\DLLs', 'd:\\\\env\\\\pytorch\\\\lib', 'd:\\\\env\\\\pytorch\\\\scripts', 'c:\\\\users\\\\11025\\\\appdata\\\\local\\\\programs\\\\python\\\\python36\\\\Lib', 'c:\\\\users\\\\11025\\\\appdata\\\\local\\\\programs\\\\python\\\\python36\\\\DLLs', 'd:\\\\env\\\\pytorch', '', 'd:\\\\env\\\\pytorch\\\\lib\\\\site-packages', 'd:\\\\env\\\\pytorch\\\\lib\\\\site-packages\\\\IPython\\\\extensions', 'C:\\\\Users\\\\11025\\\\.ipython']\n",
      "3.6.8 (tags/v3.6.8:3c6b436a57, Dec 24 2018, 00:16:47) [MSC v.1916 64 bit (AMD64)]\n",
      "d:\\env\\pytorch\\scripts\\python.exe\n"
     ]
    }
   ],
   "source": [
    "import sys\n",
    "print(sys.path)\n",
    "print(sys.version)\n",
    "print(sys.executable)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
